package handlers;

import java.awt.Color;
import java.util.Random;

import main.MainMap;
import main.MainMenu;
import people.Character;
import people.Enemy;

public class EnemyAttackHandler {

	static String type;
	
	public static void handle(Character mob, int attackType, Enemy attacker) {
		// Attack Types:
				// 0 = melee
				// 1 = ranged
				// 2 = magic
				int dmg = -1;
				Character c = Character.c;
				Random rand = new Random();
				switch (attackType) {
					case 0: 
						if ((rand.nextInt(mob.stats[3]) > c.stats[5])) {
							dmg = -1;
						}
						else {
							dmg = (c.stats[2] * 2) - ((mob.stats[3] / 2) + (mob.stats[5]));
							mob.health = mob.health - dmg;
						}
						break;
					case 1: 
						if (mob.stats[3] > c.stats[5 ]) {
							dmg = -1;
						}
						else {
							dmg = (c.stats[2]) + (c.stats[3] / 4);
							mob.health = mob.health - dmg;
						}
						break;
					case 2:
						int mana_cost = rand.nextInt(5);
						c.mana = c.mana - mana_cost; 
						dmg = c.stats[4] - ((mob.stats[5]) / 2);
						mob.health = mob.health - dmg;
						break;
				}
				if (mob.health < 1) {
					mob = null;
					MainMap.mainMap.map[c.x][c.y].setBackground(Color.GREEN);
					MainMap.stats.recalcStats();
					MainMenu.printInfo("\r\nYou have died\r\n");
					type = null;
					MainMap.navi.dispose();
				}
				else {
					MainMap.stats.recalcStats();
				}
			} 

	public static void initType() {
		type = PlayerAttackHandler.type;
	}
}

